const app = getApp();
const Controller = require('../controllers/controllers.js').controller;

Page({
  data: {
    
     userInfo:{},

    //权限鉴定

     roleType:1,

    //是否登录
      isLogin:true,
    

      //是否有消息
      hasMessage:true,
      //是否分享
      isOpenShare:false
  
  },
  
  onLoad:function(option){
    
  

  },
  onShow:function(){
 
    if (!wx.getStorageSync('logintoken')) {
       this.setData({
         userInfo:{}
       })
       this.goLogin()
    }else{
  
      this.info()
      this.checkUnReadNoticeCount()
    }

  },
  info(){
   

  
     
     
    //  return
   let that=this
  Controller.info({}).then(res=>{
    let that=this
        let baseData=res.data.baseData
        that.setData({
          userInfo:baseData,
          roleType:baseData.roleType
        })
        
    
   
  })


  },
  //获取未读消息数量·
  checkUnReadNoticeCount(){
   Controller.checkUnReadNoticeCount({}).then(res=>{
     let baseData=res.data.baseData
      this.setData({
        hasMessage:baseData>0?true:false
      })
   })
  },

  
 
  closeShare(e){
   this.setData({
    isOpenShare:false
   })
  },
  
  golink(e){

  
    if (!wx.getStorageSync('logintoken')) {
      this.goLogin()
      return
    }

    
    var url=e.target.dataset.url;
    
    if(url=='share'){
     
      Controller.userMakeShare({}).then(res=>{
        
      })
      
       this.setData({
         isOpenShare:true
       })
    }else{
      wx.navigateTo({
        url: url
      })
    }

   
  },

  goLogin(e){
    app.ToLogin(true)
  },
  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
})